package leetcode_2301_2400;

public class LeeCode_2367 {
    public static void main(String[] args) {
        System.out.println(arithmeticTriplets(new int[]{0, 1, 4, 6, 7, 10}, 3));
    }
    private static int arithmeticTriplets(int[] nums, int diff) {
        int res = 0;
        for (int i = 1; i < nums.length - 1; i++) {
            int l = i - 1, r = i + 1;
            while (l >= 0 && nums[i] - nums[l] < diff){
                l--;
            }
            if (l < 0)
                continue;
            while (r < nums.length && nums[r] - nums[i] < diff){
                r++;
            }
            if (r >= nums.length)
                continue;
            if (nums[r] - nums[i] == diff && nums[i] - nums[l] == diff)
                res++;
        }
        return res;
    }
}
